package file;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 * Creared with IntelliJ IDEA.
 * Description:按字符来写
 * User:yxd
 * Date:2022-04-08
 * Time:15:11
 */
public class Demo11 {
    public static void main(String[] args) {
        try(Reader reader = new FileReader("E:/NEW/test.txt")) {
            while (true){
                char[] c = new char[1024];
                int x = reader.read(c);//一次读多个
                if(x == -1){
                    break;
                }
                /*for (int i = 0; i < x; i++) {
                    System.out.println(c[i]);

                }*/
                String s = new String(c,0,x);//如果传入的是byte也可以指定字符编码
                System.out.println(s);//这样也可以读
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
